﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Data.SqlClient;

namespace OA_WEB.GCGLB.SCGL
{
    public partial class SC_GYGDZCImport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button1_Click1(object sender, EventArgs e)
        {
            ZWL.BLL.SC_GYGDZC fileSvr = new ZWL.BLL.SC_GYGDZC();//导入处理类
            string filename = FileUpload1.PostedFile.FileName.ToString();//客户端文件名
            string fileExtension = filename.Substring(filename.LastIndexOf("."));//文件扩展名
            string fileSubName = filename.Substring(0, filename.LastIndexOf("."));//不带扩展名的文件名
            int filesize = FileUpload1.PostedFile.ContentLength;//文件大小
            if (filesize < 1024 * 1024 * 5)
            {
                string path = Server.MapPath("~/ExcelData/StuffLibarys/");//excel文件服务器端保存路径
                string savePath = System.DateTime.Now.ToString("yyyymmddhhmmss") + fileExtension;
                FileUpload1.SaveAs(path + savePath);
                System.Data.DataTable dt = fileSvr.GetExcelDatatable(path + savePath, "mapTable");
                fileSvr.SqlBulkCopyInsetData(dt);
                Response.Write("<script>alert('批量导入完成');</script>");
            }
            else
            {
                Response.Write("<script>alert('批量导入时发生错误！请重新登陆后重试！');</script>");
            }
        }
        protected void Delete_Click(object sender, EventArgs e)
        {
            if (ZWL.DBUtility.DbHelperSQL.ExecuteSQL("delete from StuffLibrary") == -1)
            {
                Response.Write("<script>alert('清空库时发生错误！请重新登陆后重试！');</script>");
            }
            else
            {
                Response.Write("<script>alert('清空完成。');</script>");
                //写系统日志
                ZWL.BLL.ERPRiZhi MyRiZhi = new ZWL.BLL.ERPRiZhi();
                MyRiZhi.UserName = ZWL.Common.PublicMethod.GetSessionValue("UserName");
                MyRiZhi.DoSomething = "用户清空集体资产库库基本信息";
                MyRiZhi.IpStr = System.Web.HttpContext.Current.Request.UserHostAddress.ToString();
                MyRiZhi.Add();
            }
        }
    }
}